package com.ruoyi.fun.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.annotation.DataScope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fun.mapper.EcOrderItemMapper;
import com.ruoyi.fun.domain.EcOrderItem;
import com.ruoyi.fun.service.IEcOrderItemService;

/**
 * 订单商品Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-06
 */
@Service
public class EcOrderItemServiceImpl implements IEcOrderItemService 
{
    @Autowired
    private EcOrderItemMapper ecOrderItemMapper;

    /**
     * 查询订单商品
     * 
     * @param orderItemId 订单商品主键
     * @return 订单商品
     */
    @Override
    @DataScope(userAlias = "o", permission = "fun:item:query")
    public EcOrderItem selectEcOrderItemByOrderItemId(Long orderItemId)
    {
        return ecOrderItemMapper.selectEcOrderItemByOrderItemId(orderItemId);
    }

    /**
     * 查询订单商品列表
     * 
     * @param ecOrderItem 订单商品
     * @return 订单商品
     */
    @Override
    @DataScope(userAlias = "o", permission = "fun:item:list")
    public List<EcOrderItem> selectEcOrderItemList(EcOrderItem ecOrderItem)
    {
        return ecOrderItemMapper.selectEcOrderItemList(ecOrderItem);
    }

    /**
     * 新增订单商品
     * 
     * @param ecOrderItem 订单商品
     * @return 结果
     */
    @Override
    public int insertEcOrderItem(EcOrderItem ecOrderItem)
    {
        ecOrderItem.setCreateTime(DateUtils.getNowDate());
        // orgId应该由Controller层传入，不在Service层设置默认值
        return ecOrderItemMapper.insertEcOrderItem(ecOrderItem);
    }

    /**
     * 修改订单商品
     * 
     * @param ecOrderItem 订单商品
     * @return 结果
     */
    @Override
    public int updateEcOrderItem(EcOrderItem ecOrderItem)
    {
        return ecOrderItemMapper.updateEcOrderItem(ecOrderItem);
    }

    /**
     * 批量删除订单商品
     * 
     * @param orderItemIds 需要删除的订单商品主键
     * @return 结果
     */
    @Override
    public int deleteEcOrderItemByOrderItemIds(Long[] orderItemIds)
    {
        return ecOrderItemMapper.deleteEcOrderItemByOrderItemIds(orderItemIds);
    }

    /**
     * 删除订单商品信息
     * 
     * @param orderItemId 订单商品主键
     * @return 结果
     */
    @Override
    public int deleteEcOrderItemByOrderItemId(Long orderItemId)
    {
        return ecOrderItemMapper.deleteEcOrderItemByOrderItemId(orderItemId);
    }

    /**
     * 根据orderItemId和组织ID查询OrderItem
     * 
     * @param orderItemId OrderItem主键
     * @param orgId 组织ID
     * @return OrderItem
     */
    @Override
    public EcOrderItem selectEcOrderItemByOrderItemIdAndOrgId(Long orderItemId, Long orgId)
    {
        return ecOrderItemMapper.selectEcOrderItemByOrderItemIdAndOrgId(orderItemId, orgId);
    }

    /**
     * 根据组织ID查询OrderItem列表
     * 
     * @param ecorderitem OrderItem
     * @param orgId 组织ID
     * @return OrderItem集合
     */
    @Override
    public List<EcOrderItem> selectEcOrderItemListByOrgId(EcOrderItem ecorderitem, Long orgId)
    {
        return ecOrderItemMapper.selectEcOrderItemListByOrgId(orgId);
    }
}
